<!DOCTYPE html>
<html CN>







<head>
	
	
	<link rel="stylesheet" href="/css/allinone.min.css"> 

	
	<!-- Global Site Tag (gtag.js) - Google Analytics -->
	<script async src="https://www.googletagmanager.com/gtag/js?id=UA-42863699-1"></script>
	<script>
		window.dataLayer = window.dataLayer || [];
		function gtag(){dataLayer.push(arguments);}
		gtag('js', new Date());
		gtag('config', 'UA-42863699-1');
	</script>
	

	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />

	<title>kubernetes 简介： kubelet 和 pod | Cizixs Write Here</title>

	<meta name="HandheldFriendly" content="True" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="generator" content="hexo">
	<meta name="author" content="Cizixs Wu">
	<meta name="description" content="">

	
	<meta name="keywords" content="">
	

	
	<link rel="shortcut icon" href="https://cizixs-blog.oss-cn-beijing.aliyuncs.com/006tNc79ly1g1qxfovpzyj30740743yg.jpg">
	

	
	<meta name="theme-color" content="#3c484e">
	<meta name="msapplication-TileColor" content="#3c484e">
	

	

	

	<meta property="og:site_name" content="Cizixs Write Here">
	<meta property="og:type" content="article">
	<meta property="og:title" content="kubernetes 简介： kubelet 和 pod | Cizixs Write Here">
	<meta property="og:description" content="">
	<meta property="og:url" content="http://cizixs.com/2016/10/25/kubernetes-intro-kubelet/">

	
	<meta property="article:published_time" content="2016-10-25T00:10:00+08:00"/> 
	<meta property="article:author" content="Cizixs Wu">
	<meta property="article:published_first" content="Cizixs Write Here, /2016/10/25/kubernetes-intro-kubelet/" />
	

	
	
	<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
	

	
	<script src="https://cdn.staticfile.org/highlight.js/9.10.0/highlight.min.js"></script>
	

	
	
<link rel="stylesheet" href="/css/prism-base16-ateliersulphurpool.light.css" type="text/css"></head>
<body class="post-template">
    <div class="site-wrapper">
        




<header class="site-header outer" style="z-index: 999">
    <div class="inner">
        
<nav class="site-nav"> 
    <div class="site-nav-left">
        <ul class="nav">
            <li>
                
                <a href="/" title="Home">Home</a>
                
            </li>
            
            
            <li>
                <a href="/about" title="About">About</a>
            </li>
            
            <li>
                <a href="/archives" title="Archives">Archives</a>
            </li>
            
            
        </ul> 
    </div>
    <div class="site-nav-right">
        
<div class="social-links" >
    
    <a class="social-link" title="weibo" href="https://weibo.com/1921727853" target="_blank" rel="noopener">
        <svg viewBox="0 0 1141 1024" xmlns="http://www.w3.org/2000/svg"><path d="M916.48 518.144q27.648 21.504 38.912 51.712t9.216 62.976-14.336 65.536-31.744 59.392q-34.816 48.128-78.848 81.92t-91.136 56.32-94.72 35.328-89.6 18.944-75.264 7.68-51.712 1.536-49.152-2.56-68.096-10.24-78.336-21.504-79.872-36.352-74.24-55.296-59.904-78.848q-16.384-29.696-22.016-63.488t-5.632-86.016q0-22.528 7.68-51.2t27.136-63.488 53.248-75.776 86.016-90.112q51.2-48.128 105.984-85.504t117.248-57.856q28.672-10.24 63.488-11.264t57.344 11.264q10.24 11.264 19.456 23.04t12.288 29.184q3.072 14.336 0.512 27.648t-5.632 26.624-5.12 25.6 2.048 22.528q17.408 2.048 33.792-1.536t31.744-9.216 31.232-11.776 33.28-9.216q27.648-5.12 54.784-4.608t49.152 7.68 36.352 22.016 17.408 38.4q2.048 14.336-2.048 26.624t-8.704 23.04-7.168 22.016 1.536 23.552q3.072 7.168 14.848 13.312t27.136 12.288 32.256 13.312 29.184 16.384zM658.432 836.608q26.624-16.384 53.76-45.056t44.032-64 18.944-75.776-20.48-81.408q-19.456-33.792-47.616-57.344t-62.976-37.376-74.24-19.968-80.384-6.144q-78.848 0-139.776 16.384t-105.472 43.008-72.192 60.416-38.912 68.608q-11.264 33.792-6.656 67.072t20.992 62.976 42.496 53.248 57.856 37.888q58.368 25.6 119.296 32.256t116.224 0.512 100.864-21.504 74.24-33.792zM524.288 513.024q20.48 8.192 38.912 18.432t32.768 27.648q10.24 12.288 17.92 30.72t10.752 39.424 1.536 42.496-9.728 38.912q-8.192 18.432-19.968 37.376t-28.672 35.328-40.448 29.184-57.344 18.944q-61.44 11.264-117.76-11.264t-88.064-74.752q-12.288-39.936-13.312-70.656t16.384-66.56q13.312-27.648 40.448-51.712t62.464-38.912 75.264-17.408 78.848 12.8zM361.472 764.928q37.888 3.072 57.856-18.432t21.504-48.128-15.36-47.616-52.736-16.896q-27.648 3.072-43.008 23.552t-17.408 43.52 9.728 42.496 39.424 21.504zM780.288 6.144q74.752 0 139.776 19.968t113.664 57.856 76.288 92.16 27.648 122.88q0 33.792-16.384 50.688t-35.328 17.408-35.328-14.336-16.384-45.568q0-40.96-22.528-77.824t-59.392-64.512-84.48-43.52-96.768-15.872q-31.744 0-47.104-15.36t-14.336-34.304 18.944-34.304 51.712-15.36zM780.288 169.984q95.232 0 144.384 48.64t49.152 146.944q0 30.72-10.24 43.52t-22.528 11.264-22.528-14.848-10.24-35.84q0-60.416-34.816-96.256t-93.184-35.84q-19.456 0-28.672-10.752t-9.216-23.04 9.728-23.04 28.16-10.752z" /></svg>
    </a>
    

    
    <a class="social-link" title="github" href="https://github.com/cizixs" target="_blank" rel="noopener">
        <svg viewBox="0 0 1049 1024" xmlns="http://www.w3.org/2000/svg"><path d="M524.979332 0C234.676191 0 0 234.676191 0 524.979332c0 232.068678 150.366597 428.501342 358.967656 498.035028 26.075132 5.215026 35.636014-11.299224 35.636014-25.205961 0-12.168395-0.869171-53.888607-0.869171-97.347161-146.020741 31.290159-176.441729-62.580318-176.441729-62.580318-23.467619-60.841976-58.234462-76.487055-58.234463-76.487055-47.804409-32.15933 3.476684-32.15933 3.476685-32.15933 53.019436 3.476684 80.83291 53.888607 80.83291 53.888607 46.935238 79.963739 122.553122 57.365291 152.97411 43.458554 4.345855-33.897672 18.252593-57.365291 33.028501-70.402857-116.468925-12.168395-239.022047-57.365291-239.022047-259.012982 0-57.365291 20.860106-104.300529 53.888607-140.805715-5.215026-13.037566-23.467619-66.926173 5.215027-139.067372 0 0 44.327725-13.906737 144.282399 53.888607 41.720212-11.299224 86.917108-17.383422 131.244833-17.383422s89.524621 6.084198 131.244833 17.383422C756.178839 203.386032 800.506564 217.29277 800.506564 217.29277c28.682646 72.1412 10.430053 126.029806 5.215026 139.067372 33.897672 36.505185 53.888607 83.440424 53.888607 140.805715 0 201.64769-122.553122 245.975415-239.891218 259.012982 19.121764 16.514251 35.636014 47.804409 35.636015 97.347161 0 70.402857-0.869171 126.898978-0.869172 144.282399 0 13.906737 9.560882 30.420988 35.636015 25.205961 208.601059-69.533686 358.967656-265.96635 358.967655-498.035028C1049.958663 234.676191 814.413301 0 524.979332 0z" /></svg>
    </a>
    

    
    <a class="social-link" title="stackoverflow" href="https://stackoverflow.com/users/1925083/cizixs" target="_blank" rel="noopener">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M15 21h-10v-2h10v2zm6-11.665l-1.621-9.335-1.993.346 1.62 9.335 1.994-.346zm-5.964 6.937l-9.746-.975-.186 2.016 9.755.879.177-1.92zm.538-2.587l-9.276-2.608-.526 1.954 9.306 2.5.496-1.846zm1.204-2.413l-8.297-4.864-1.029 1.743 8.298 4.865 1.028-1.744zm1.866-1.467l-5.339-7.829-1.672 1.14 5.339 7.829 1.672-1.14zm-2.644 4.195v8h-12v-8h-2v10h16v-10h-2z"/></svg>
    </a>
    

    

    
    <a class="social-link" title="twitter" href="https://twitter.com/cizixs" target="_blank" rel="noopener">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M30.063 7.313c-.813 1.125-1.75 2.125-2.875 2.938v.75c0 1.563-.188 3.125-.688 4.625a15.088 15.088 0 0 1-2.063 4.438c-.875 1.438-2 2.688-3.25 3.813a15.015 15.015 0 0 1-4.625 2.563c-1.813.688-3.75 1-5.75 1-3.25 0-6.188-.875-8.875-2.625.438.063.875.125 1.375.125 2.688 0 5.063-.875 7.188-2.5-1.25 0-2.375-.375-3.375-1.125s-1.688-1.688-2.063-2.875c.438.063.813.125 1.125.125.5 0 1-.063 1.5-.25-1.313-.25-2.438-.938-3.313-1.938a5.673 5.673 0 0 1-1.313-3.688v-.063c.813.438 1.688.688 2.625.688a5.228 5.228 0 0 1-1.875-2c-.5-.875-.688-1.813-.688-2.75 0-1.063.25-2.063.75-2.938 1.438 1.75 3.188 3.188 5.25 4.25s4.313 1.688 6.688 1.813a5.579 5.579 0 0 1 1.5-5.438c1.125-1.125 2.5-1.688 4.125-1.688s3.063.625 4.188 1.813a11.48 11.48 0 0 0 3.688-1.375c-.438 1.375-1.313 2.438-2.563 3.188 1.125-.125 2.188-.438 3.313-.875z"/></svg>

    </a>
    

    
    <a class="social-link" title="instagram" href="https://www.instagram.com/cizixs/" target="_blank" rel="noopener">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/></svg>
    </a>
    
    
    
</div>
    </div>
</nav>
    </div>
</header>


<main id="site-main" class="site-main outer" role="main">
    <div class="inner">
        <header class="post-full-header">
            <section class="post-full-meta">
                <time  class="post-full-meta-date" datetime="2016-10-24T16:00:00.000Z" itemprop="datePublished">
                    2016-10-25
                </time>
                
                <span class="date-divider">/</span>
                
                <a href="/categories/blog/">blog</a>&nbsp;&nbsp;
                
                
            </section>
            <h1 class="post-full-title">kubernetes 简介： kubelet 和 pod</h1>
        </header>
        <article class="post-full no-image">
            
            <section class="post-full-content">
                <div id="lightgallery" class="markdown-body">
                    <h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p><a href="http://cizixs.com/2016/07/12/kubernetes-intro">kubernetes</a> 是一个分布式的集群管理系统，在每个节点（node）上都要运行一个 worker 对容器进行生命周期的管理，这个 worker 程序就是 <code>kubelet</code>。</p>
<p>简单地说，<code>kubelet</code> 的主要功能就是定时从某个地方获取节点上 pod/container 的期望状态（运行什么容器、运行的副本数量、网络或者存储如何配置等等），并调用对应的容器平台接口达到这个状态。</p>
<p>集群状态下，kubelet 会从 master 上读取信息，但其实 kubelet 还可以从其他地方获取节点的 pod 信息。目前 kubelet 支持三种数据源：</p>
<p><img src="https://cizixs-blog.oss-cn-beijing.aliyuncs.com/006y8lVagw1f8vkhdub9zj31hc0u0djl.jpg" alt="kubelet architecture"></p>
<ol>
<li>本地文件</li>
<li>通过 url 从网络上某个地址来获取信息</li>
<li>API Server：从 kubernetes master 节点获取信息</li>
</ol>
<p>从管理的对象来说，kubelet 目前支持 <a href="https://www.docker.com/" target="_blank" rel="noopener">docker</a> 和 <a href="https://coreos.com/rkt/" target="_blank" rel="noopener">rkt</a>，默认情况下使用的 docker。</p>
<h2 id="kubelet-主要功能"><a href="#kubelet-主要功能" class="headerlink" title="kubelet 主要功能"></a>kubelet 主要功能</h2><h3 id="pod-管理"><a href="#pod-管理" class="headerlink" title="pod 管理"></a>pod 管理</h3><p> 在 kubernetes 的设计中，最基本的管理单位是 pod，而不是 container。pod 是 kubernetes 在容器上的一层封装，由一组运行在同一主机的一个或者多个容器组成。如果把容器比喻成传统机器上的一个进程（它可以执行任务，对外提供某种功能），那么 pod 可以类比为传统的主机：它包含了多个容器，为它们提供共享的一些资源。</p>
<p><img src="https://cizixs-blog.oss-cn-beijing.aliyuncs.com/006y8lVagw1f93i3nzo9aj30yg0lptc6.jpg" alt=""></p>
<p>之所以费功夫提供这一层封装，主要是因为容器推荐的用法是里面只运行一个进程，而一般情况下某个应用都由多个组件构成的。</p>
<p>pod 中所有的容器最大的特性也是最大的好处就是共享了很多资源，比如网络空间。pod 下所有容器共享网络和端口空间，也就是它们之间可以通过 <code>localhost</code> 访问和通信，对外的通信方式也是一样的，省去了很多容器通信的麻烦。</p>
<p>除了网络之外，定义在 pod 里的 volume 也可以 mount 到多个容器里，以实现共享的目的。</p>
<p>最后，定义在 pod 的资源限制（比如 CPU 和 Memory） 也是所有容器共享的。</p>
<h3 id="容器健康检查"><a href="#容器健康检查" class="headerlink" title="容器健康检查"></a>容器健康检查</h3><p>创建了容器之后，kubelet 还要查看容器是否正常运行，如果容器运行出错，就要根据设置的重启策略进行处理。检查容器是否健康主要有两种方式：在容器中执行命令和通过 HTTP 访问预定义的 endpoint。</p>
<p>先来说说执行命令的方式，简单来说就是在容器中执行某个 shell 命令，根据它的 exit code 来判断容器是否正常工作：</p>
<pre><code>livenessProbe:
      exec:
        command:
        - cat
        - /tmp/health
      initialDelaySeconds: 15
      timeoutSeconds: 1
</code></pre><p>另外一种就是 HTTP 的方式，通过向某个 url 路径发送 HTTP GET 请求，根据 response code 判断容器是否正常工作：</p>
<pre><code>livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
          - name: X-Custom-Header
            value: Awesome
      initialDelaySeconds: 15
      timeoutSeconds: 1
</code></pre><p>可以看到，你也可以自定义发送的 HTTP 请求的头部。</p>
<p>不管用什么方式，如果检测到容器不健康，kubelet 会删除该容器，并根据容器的重启策略进行处理（比如重启，或者什么都不做）。</p>
<h3 id="容器监控"><a href="#容器监控" class="headerlink" title="容器监控"></a>容器监控</h3><p>kubelet 还有一个重要的责任，就是监控所在节点的资源使用情况，并定时向 master 报告。知道整个集群所有节点的资源情况，对于 pod 的调度和正常运行至关重要。</p>
<p>kubelet 使用 <a href="https://github.com/google/cadvisor" target="_blank" rel="noopener">cAdvisor</a> 进行资源使用率的监控。cAdvisor 是 google 开源的分析容器资源使用和性能特性的工具，在 kubernetes 项目中被集成到 kubelet 里，无需额外配置。默认情况下，你可以在 <code>http://&lt;host_ip&gt;:4194</code> 地址看到 cAdvisor 的管理界面。</p>
<blockquote>
<p>Analyzes resource usage and performance characteristics of running containers.</p>
</blockquote>
<p>除了系统使用的 CPU，Memory，存储和网络之外，cAdvisor 还记录了每个容器使用的上述资源情况。</p>
<h2 id="运行和验证-kubelet"><a href="#运行和验证-kubelet" class="headerlink" title="运行和验证 kubelet"></a>运行和验证 kubelet</h2><h3 id="参数介绍"><a href="#参数介绍" class="headerlink" title="参数介绍"></a>参数介绍</h3><p>对于 kubelet 的配置，基本上都可以通过命令行启动时候的参数进行控制。因为 kubernetes 处于快速开发过程中，参数也可能会发生变化，这里给出 <code>1.4</code> 版本一些重要的参数含义：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>解释</th>
<th>默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td>–address</td>
<td>kubelet 服务监听的地址</td>
<td>0.0.0.0</td>
</tr>
<tr>
<td>–port</td>
<td>kubelet 服务监听的端口</td>
<td>10250</td>
</tr>
<tr>
<td>–read-only-port</td>
<td>只读端口，可以不用验证和授权机制，直接访问</td>
<td>10255</td>
</tr>
<tr>
<td>–allow-privileged</td>
<td>是否允许容器运行在 privileged 模式</td>
<td>false</td>
</tr>
<tr>
<td>–api-servers</td>
<td>以逗号分割的 API Server 地址，用于和集群中数据交互</td>
<td>[]</td>
</tr>
<tr>
<td>–cadvisor-port</td>
<td>当前节点 cadvisor 运行的端口</td>
<td>4194</td>
</tr>
<tr>
<td>–config</td>
<td>本地 manifest 文件的路径或者目录</td>
<td>“”</td>
</tr>
<tr>
<td>–file-check-frequency</td>
<td>轮询本地 manifest 文件的时间间隔</td>
<td>20s</td>
</tr>
<tr>
<td>–container-runtime</td>
<td>后端容器 runtime，支持 docker 和 rkt</td>
<td>docker</td>
</tr>
<tr>
<td>–enable-server</td>
<td>是否启动 kubelet HTTP server</td>
<td>true</td>
</tr>
<tr>
<td>–healthz-bind-address</td>
<td>健康检查服务绑定的地址，设置成 0.0.0.0 可以监听在所有网络接口</td>
<td>127.0.0.1</td>
</tr>
<tr>
<td>–healthz-port</td>
<td>健康检查服务的端口</td>
<td>10248</td>
</tr>
<tr>
<td>–hostname-override</td>
<td>指定 hostname，如果非空会使用这个值作为节点在集群中的标识</td>
<td>“”</td>
</tr>
<tr>
<td>–log-dir</td>
<td>日志文件，如果非空，会把 log 写到该文件</td>
<td>“”</td>
</tr>
<tr>
<td>–logtostderr</td>
<td>是否打印 log 到终端</td>
<td>true</td>
</tr>
<tr>
<td>–max-open-files</td>
<td>允许 kubelet 打开文件的最大值</td>
<td>1000000</td>
</tr>
<tr>
<td>–max-pods</td>
<td>允许 kubelet 运行 pod 的最大值</td>
<td>110</td>
</tr>
<tr>
<td>–pod-infra-container-image</td>
<td>基础镜像地址，每个 pod 最先启动的容器，会配置共享的网络</td>
<td>gcr.io/google_containers/pause-amd64:3.0</td>
</tr>
<tr>
<td>–root-dir</td>
<td>kubelet 保存数据的目录</td>
<td>/var/lib/kubelet</td>
</tr>
<tr>
<td>–runonce</td>
<td>从本地 manifest 或者 URL 指定的 manifest 读取并运行结束就退出，和 <code>--api-servers</code> 、<code>--enable-server</code> 参数不兼容</td>
</tr>
<tr>
<td>–v</td>
<td>日志 level</td>
<td>0</td>
</tr>
</tbody>
</table>
<h3 id="启动-kubelet"><a href="#启动-kubelet" class="headerlink" title="启动 kubelet"></a>启动 kubelet</h3><p>在这篇教程中，我们会单独运行 kubelet，选择从本地目录中读取 pod manifest 信息去启动 pod。</p>
<pre><code>[Unit]
Description=Kubelet Service
Documentation=http://kubernetes.com
After=network.target
Wants=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests
ExecStart=/usr/bin/kubelet \
    --allow-privileged=true \
    --config=/etc/kubernetes/manifests \
    --pod-infra-container-image=172.16.1.41:5000/google_containers/pause:0.8.0 \
    --hostname-override=192.168.8.100
TimeoutStartSec=0
Restart=on-abnormal

[Install]
WantedBy=multi-user.target
</code></pre><p>在这篇文章的例子中，我们会运行一个 pod，这个 pod 有两个容器：nginx 和 busybox。<br>nginx 不做任何修改，只是提供简单的 HTTP 服务；busybox 运行命令，在终端打印出 nginx 的访问日志。为了实现两个容器之间共享数据，我们使用 kubernetes 提供的 Volume 功能，</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx-server
spec:
  containers:
  - name: nginx-server
    image: 172.16.1.41:5000/nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: /var/log/nginx
      name: nginx-logs
  - name: log-output
    image: 172.16.1.41:5000/busybox
    command:
    - bin/sh
    args: [-c, &#39;tail -f /logdir/access.log&#39;]
    volumeMounts:
    - mountPath: /logdir
      name: nginx-logs
  volumes:
  - name: nginx-logs
    emptyDir: {}
</code></pre><p>把这个配置文件放到指定的目录，等待一段时间，我们就能 <code>docker ps</code> 看到有容器在运行了：</p>
<pre><code>[root@localhost vagrant]# docker ps
CONTAINER ID        IMAGE                                            COMMAND                  CREATED             STATUS              PORTS               NAMES
66474b8cc336        172.16.1.41:5000/busybox                         &quot;bin/sh -c &#39;tail -f /&quot;   6 days ago          Up 6 days                               k8s_log-output.b93a0be3_nginx-server-192.168.8.100_default_dae69c6f50364bf8fcf20bc67f42a416_22c30949
90ab8ef86868        172.16.1.41:5000/nginx                           &quot;nginx&quot;                  6 days ago          Up 6 days                               k8s_nginx-server.b88325ae_nginx-server-192.168.8.100_default_dae69c6f50364bf8fcf20bc67f42a416_e152bb97
db27cfa9f58f        172.16.1.41:5000/google_containers/pause:0.8.0   &quot;/pause&quot;                 6 days ago          Up 6 days                               k8s_POD.b66e0279_nginx-server-192.168.8.100_default_dae69c6f50364bf8fcf20bc67f42a416_2236d469
</code></pre><p>我们可以看到三个容器：pause、nginx 和 busybox，容器的名字是 kubelet 自动生成的。通过 <code>docker inspect</code> 可以看到 nginx 和 busybox 的网络模式：</p>
<pre><code>[root@localhost vagrant]# docker inspect -f &#39;{{ .HostConfig.NetworkMode }}&#39; 90ab
container:db27cfa9f58f7b1047fb230da951453ca15e0961ca36ee7999ab3ed8ba5da814

[root@localhost vagrant]# docker inspect -f &#39;{{ .HostConfig.NetworkMode }}&#39; 6647
container:db27cfa9f58f7b1047fb230da951453ca15e0961ca36ee7999ab3ed8ba5da814
</code></pre><p>使用的是 <code>container</code> 模式，对应的 id 就是 pause 容器的。通过查看各个容器的网络配置也能验证这一点，所有的容器网络都是一样的：</p>
<pre><code>[root@localhost vagrant]# docker exec 90ab ip addr
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
9: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:2/64 scope link tentative dadfailed
       valid_lft forever preferred_lft forever
</code></pre><p>而 nginx 和 busybox 的配置信息中并没有 ip 地址，pause 容器中有：</p>
<pre><code>[root@localhost vagrant]# docker inspect -f &#39;{{ .NetworkSettings.IPAddress}}&#39; 6647

[root@localhost vagrant]# docker inspect -f &#39;{{ .NetworkSettings.IPAddress}}&#39; 90ab

[root@localhost vagrant]# docker inspect -f &#39;{{ .NetworkSettings.IPAddress}}&#39; db27
172.17.0.2
</code></pre><p>好了，分析就这么多。我们看测试一下启动的容器是否正常，先通过 <code>curl</code> 访问几次 nginx：</p>
<pre><code>[root@localhost vagrant]# curl -s http://172.17.0.2 | head -n 5
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx on Debian!&lt;/title&gt;
&lt;style&gt;
</code></pre><p>然后通过 busybox 容器查看访问日志：</p>
<pre><code>[root@localhost vagrant]# docker logs -f 6647
172.17.0.1 - - [08/Sep/2016:03:29:47 +0000] &quot;GET / HTTP/1.1&quot; 200 867 &quot;-&quot; &quot;curl/7.29.0&quot;
172.17.0.1 - - [08/Sep/2016:03:49:57 +0000] &quot;GET / HTTP/1.1&quot; 200 867 &quot;-&quot; &quot;curl/7.29.0&quot;
172.17.0.1 - - [08/Sep/2016:03:50:18 +0000] &quot;GET / HTTP/1.1&quot; 200 867 &quot;-&quot; &quot;curl/7.29.0&quot;
172.17.0.1 - - [08/Sep/2016:03:50:23 +0000] &quot;GET / HTTP/1.1&quot; 200 867 &quot;-&quot; &quot;curl/7.29.0&quot;
</code></pre><p>随着请求的发送，可以看到日志都打印出来了。</p>
<h3 id="API-接口"><a href="#API-接口" class="headerlink" title="API 接口"></a>API 接口</h3><p>前面也提到了，kubelet 自身提供了几个 HTTP API 接口，供用户查看信息。<br>最简单的就是 10248 的健康检查：</p>
<pre><code>[root@localhost vagrant]# curl http://127.0.0.1:10248/healthz
ok
</code></pre><p>而 10255 端口比较重要，提供了 pod 和机器的信息：</p>
<pre><code>➜  ~ http http://192.168.8.100:10255/pods
HTTP/1.1 200 OK
Content-Length: 1345
Content-Type: application/json
Date: Thu, 08 Sep 2016 04:03:38 GMT

{
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;items&quot;: [
        {
            &quot;metadata&quot;: {
                &quot;annotations&quot;: {
                    &quot;kubernetes.io/config.hash&quot;: &quot;bf570970380d322fa28f20a8fe4b61bc&quot;,
                    &quot;kubernetes.io/config.seen&quot;: &quot;2016-09-01T09:50:16.379538472+02:00&quot;,
                    &quot;kubernetes.io/config.source&quot;: &quot;file&quot;
                },
                &quot;creationTimestamp&quot;: null,
                &quot;name&quot;: &quot;nginx-server-192.168.8.100&quot;,
                &quot;namespace&quot;: &quot;default&quot;,
                &quot;selfLink&quot;: &quot;/api/v1/pods/namespaces/nginx-server-192.168.8.100/default&quot;,
                &quot;uid&quot;: &quot;dae69c6f50364bf8fcf20bc67f42a416&quot;
            },
            &quot;spec&quot;: {
                &quot;containers&quot;: [
                    {
                        &quot;image&quot;: &quot;172.16.1.41:5000/nginx&quot;,
                        &quot;imagePullPolicy&quot;: &quot;Always&quot;,
                        &quot;name&quot;: &quot;nginx-server&quot;,
                        &quot;ports&quot;: [
                            {
                                &quot;containerPort&quot;: 80,
                                &quot;protocol&quot;: &quot;TCP&quot;
                            }
                        ],
                        &quot;resources&quot;: {},
                        &quot;terminationMessagePath&quot;: &quot;/dev/termination-log&quot;,
                        &quot;volumeMounts&quot;: [
                            {
                                &quot;mountPath&quot;: &quot;/var/log/nginx&quot;,
                                &quot;name&quot;: &quot;nginx-logs&quot;
                            }
                        ]
                    },
                    {
                        &quot;args&quot;: [
                            &quot;-c&quot;,
                            &quot;tail -f /logdir/access.log&quot;
                        ],
                        &quot;command&quot;: [
                            &quot;bin/sh&quot;
                        ],
                        &quot;image&quot;: &quot;172.16.1.41:5000/busybox&quot;,
                        &quot;imagePullPolicy&quot;: &quot;Always&quot;,
                        &quot;name&quot;: &quot;log-output&quot;,
                        &quot;resources&quot;: {},
                        &quot;terminationMessagePath&quot;: &quot;/dev/termination-log&quot;,
                        &quot;volumeMounts&quot;: [
                            {
                                &quot;mountPath&quot;: &quot;/logdir&quot;,
                                &quot;name&quot;: &quot;nginx-logs&quot;
                            }
                        ]
                    }
                ],
                &quot;dnsPolicy&quot;: &quot;ClusterFirst&quot;,
                &quot;nodeName&quot;: &quot;192.168.8.100&quot;,
                &quot;restartPolicy&quot;: &quot;Always&quot;,
                &quot;securityContext&quot;: {},
                &quot;terminationGracePeriodSeconds&quot;: 30,
                &quot;volumes&quot;: [
                    {
                        &quot;emptyDir&quot;: {},
                        &quot;name&quot;: &quot;nginx-logs&quot;
                    }
                ]
            },
            &quot;status&quot;: {
                &quot;conditions&quot;: [
                    {
                        &quot;lastProbeTime&quot;: null,
                        &quot;lastTransitionTime&quot;: &quot;2016-09-01T07:52:36Z&quot;,
                        &quot;status&quot;: &quot;True&quot;,
                        &quot;type&quot;: &quot;PodScheduled&quot;
                    }
                ],
                &quot;phase&quot;: &quot;Pending&quot;
            }
        }
    ],
    &quot;kind&quot;: &quot;PodList&quot;,
    &quot;metadata&quot;: {}
}
</code></pre><p>pods 列出了节点上运行的 pod 信息，包括里面有多少容器、pod 的状态、一些 metadata 等。 <code>/spec/</code> 路径返回节点的信息：</p>
<pre><code>➜  ~ http http://192.168.8.100:10255/spec/
HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 08 Sep 2016 04:06:53 GMT
Transfer-Encoding: chunked

{
    &quot;boot_id&quot;: &quot;48955926-11dd-4ad3-8bb0-2585b1c9215d&quot;,
    &quot;cloud_provider&quot;: &quot;Unknown&quot;,
    &quot;cpu_frequency_khz&quot;: 2194976,
    &quot;disk_map&quot;: {
        &quot;253:0&quot;: {
            &quot;major&quot;: 253,
            &quot;minor&quot;: 0,
            &quot;name&quot;: &quot;dm-0&quot;,
            &quot;scheduler&quot;: &quot;none&quot;,
            &quot;size&quot;: 1107296256
        },
       ...
        &quot;8:0&quot;: {
            &quot;major&quot;: 8,
            &quot;minor&quot;: 0,
            &quot;name&quot;: &quot;sda&quot;,
            &quot;scheduler&quot;: &quot;cfq&quot;,
            &quot;size&quot;: 42949672960
        },
        &quot;8:16&quot;: {
            &quot;major&quot;: 8,
            &quot;minor&quot;: 16,
            &quot;name&quot;: &quot;sdb&quot;,
            &quot;scheduler&quot;: &quot;cfq&quot;,
            &quot;size&quot;: 21474836480
        },
     ...
    },
    &quot;filesystems&quot;: [
        {
            &quot;capacity&quot;: 41293721600,
            &quot;device&quot;: &quot;/dev/mapper/centos-root&quot;,
            &quot;inodes&quot;: 40345600,
            &quot;type&quot;: &quot;vfs&quot;
        },
        {
            &quot;capacity&quot;: 520794112,
            &quot;device&quot;: &quot;/dev/sda1&quot;,
            &quot;inodes&quot;: 512000,
            &quot;type&quot;: &quot;vfs&quot;
        },
        {
            &quot;capacity&quot;: 21464350720,
            &quot;device&quot;: &quot;/dev/sdb&quot;,
            &quot;inodes&quot;: 20971520,
            &quot;type&quot;: &quot;vfs&quot;
        },
       ...
    ],
    &quot;instance_id&quot;: &quot;None&quot;,
    &quot;instance_type&quot;: &quot;Unknown&quot;,
    &quot;machine_id&quot;: &quot;b9597c4ae5f24494833d35e806e00b29&quot;,
    &quot;memory_capacity&quot;: 514215936,
    &quot;network_devices&quot;: [
        {
            &quot;mac_address&quot;: &quot;08:00:27:c0:9e:5b&quot;,
            &quot;mtu&quot;: 1500,
            &quot;name&quot;: &quot;enp0s3&quot;,
            &quot;speed&quot;: 1000
        },
        {
            &quot;mac_address&quot;: &quot;08:00:27:9b:5c:b5&quot;,
            &quot;mtu&quot;: 1500,
            &quot;name&quot;: &quot;enp0s8&quot;,
            &quot;speed&quot;: 1000
        }
    ],
    &quot;num_cores&quot;: 1,
    &quot;system_uuid&quot;: &quot;823EB67A-057E-4EFF-AE7F-A758140CD2F7&quot;,
    &quot;topology&quot;: [
        {
            &quot;caches&quot;: [
                {
                    &quot;level&quot;: 3,
                    &quot;size&quot;: 3145728,
                    &quot;type&quot;: &quot;Unified&quot;
                }
            ],
            &quot;cores&quot;: [
                {
                    &quot;caches&quot;: [
                        {
                            &quot;level&quot;: 1,
                            &quot;size&quot;: 32768,
                            &quot;type&quot;: &quot;Data&quot;
                        },
                        {
                            &quot;level&quot;: 1,
                            &quot;size&quot;: 32768,
                            &quot;type&quot;: &quot;Instruction&quot;
                        },
                        {
                            &quot;level&quot;: 2,
                            &quot;size&quot;: 262144,
                            &quot;type&quot;: &quot;Unified&quot;
                        }
                    ],
                    &quot;core_id&quot;: 0,
                    &quot;thread_ids&quot;: [
                        0
                    ]
                }
            ],
            &quot;memory&quot;: 536403968,
            &quot;node_id&quot;: 0
        }
    ]
}
</code></pre><p>磁盘、网络、CPU、内存等信息，这些东西是 kubernetes 集群调度的重要依据，在集群模式中会更新到 master 节点。</p>
<h3 id="清理工作"><a href="#清理工作" class="headerlink" title="清理工作"></a>清理工作</h3><p>如果删除 <code>manifests/</code> 路径下的文件，等一段时间就会发现，kubelet 已经清空了所有的容器。</p>
<pre><code>$ curl -s http://localhost:10255/pods
{&quot;kind&quot;:&quot;PodList&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;metadata&quot;:{},&quot;items&quot;:null}
</code></pre><h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2><ul>
<li><a href="https://coreos.com/kubernetes/docs/latest/deploy-master.html" target="_blank" rel="noopener">Deploy Kubernetes Master Node(s)</a></li>
<li><a href="http://kamalmarhubi.com/blog/2015/08/27/what-even-is-a-kubelet/" target="_blank" rel="noopener">What even is a kubelet?</a></li>
<li><a href="http://kubernetes.io/docs/admin/node/" target="_blank" rel="noopener">Kubernetes Node Documentation</a></li>
<li><a href="https://coreos.com/kubernetes/docs/latest/pods.html" target="_blank" rel="noopener">Overview of a Pod</a></li>
<li><a href="http://kubernetes.io/docs/user-guide/liveness/" target="_blank" rel="noopener">Checking Pod Health</a></li>
</ul>

                </div>
            </section>
        </article>
    </div>
    
<nav class="pagination">
    
    
    <a class="prev-post" title="kubernetes 简介：API Server 和 node" href="/2016/11/07/kubernetes-intro-api-server/">
        ← kubernetes 简介：API Server 和 node
    </a>
    
    <span class="prev-next-post">•</span>
    
    <a class="next-post" title="go http 服务器编程" href="/2016/08/17/golang-http-server-side/">
        go http 服务器编程 →
    </a>
    
    
</nav>

    <div class="inner">
    <!-- Begin Mailchimp Signup Form -->
    <link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    	#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
    	/* Add your own Mailchimp form style overrides in your site stylesheet or in this style block.
    	   We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
    </style>
    <div id="mc_embed_signup">
    <form action="https://cizixs.us7.list-manage.com/subscribe/post?u=2d561b8dea52d73a2e05e6dcb&amp;id=5c710f135b" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <div id="mc_embed_signup_scroll">
    	<h2>订阅本博客，第一时间收到文章更新</h2>
    <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
    <div class="mc-field-group">
    	<label for="mce-EMAIL">邮件地址  <span class="asterisk">*</span>
    </label>
    	<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
    </div>
    	<div id="mce-responses" class="clear">
    		<div class="response" id="mce-error-response" style="display:none"></div>
    		<div class="response" id="mce-success-response" style="display:none"></div>
    	</div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_2d561b8dea52d73a2e05e6dcb_5c710f135b" tabindex="-1" value=""></div>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
        </div>
    </form>
    </div>
    <script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
    <!--End mc_embed_signup-->
    </div>

    <div class="inner">
        <div id="disqus_thread"></div>
    </div>

    
</main>

<div class="t-g-control">
    <div class="gotop">
        <svg class="icon" width="32px" height="32px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M793.024 710.272a32 32 0 1 0 45.952-44.544l-310.304-320a32 32 0 0 0-46.4 0.48l-297.696 320a32 32 0 0 0 46.848 43.584l274.752-295.328 286.848 295.808z" fill="#8a8a8a" /></svg>
    </div>
    <div class="toc-control">
        <svg class="icon toc-icon" width="32px" height="32.00px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M779.776 480h-387.2a32 32 0 0 0 0 64h387.2a32 32 0 0 0 0-64M779.776 672h-387.2a32 32 0 0 0 0 64h387.2a32 32 0 0 0 0-64M256 288a32 32 0 1 0 0 64 32 32 0 0 0 0-64M392.576 352h387.2a32 32 0 0 0 0-64h-387.2a32 32 0 0 0 0 64M256 480a32 32 0 1 0 0 64 32 32 0 0 0 0-64M256 672a32 32 0 1 0 0 64 32 32 0 0 0 0-64" fill="#8a8a8a" /></svg>
        <svg class="icon toc-close" style="display: none;" width="32px" height="32.00px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M512 960c-247.039484 0-448-200.960516-448-448S264.960516 64 512 64 960 264.960516 960 512 759.039484 960 512 960zM512 128.287273c-211.584464 0-383.712727 172.128262-383.712727 383.712727 0 211.551781 172.128262 383.712727 383.712727 383.712727 211.551781 0 383.712727-172.159226 383.712727-383.712727C895.712727 300.415536 723.551781 128.287273 512 128.287273z" fill="#8a8a8a" /><path d="M557.05545 513.376159l138.367639-136.864185c12.576374-12.416396 12.672705-32.671738 0.25631-45.248112s-32.704421-12.672705-45.248112-0.25631l-138.560301 137.024163-136.447897-136.864185c-12.512727-12.512727-32.735385-12.576374-45.248112-0.063647-12.512727 12.480043-12.54369 32.735385-0.063647 45.248112l136.255235 136.671523-137.376804 135.904314c-12.576374 12.447359-12.672705 32.671738-0.25631 45.248112 6.271845 6.335493 14.496116 9.504099 22.751351 9.504099 8.12794 0 16.25588-3.103239 22.496761-9.247789l137.567746-136.064292 138.687596 139.136568c6.240882 6.271845 14.432469 9.407768 22.65674 9.407768 8.191587 0 16.352211-3.135923 22.591372-9.34412 12.512727-12.480043 12.54369-32.704421 0.063647-45.248112L557.05545 513.376159z" fill="#8a8a8a" /></svg>
    </div>
    <div class="gobottom">
        <svg class="icon" width="32px" height="32.00px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M231.424 346.208a32 32 0 0 0-46.848 43.584l297.696 320a32 32 0 0 0 46.4 0.48l310.304-320a32 32 0 1 0-45.952-44.544l-286.848 295.808-274.752-295.36z" fill="#8a8a8a" /></svg>
    </div>
</div>
<div class="toc-main" style="right: -100%">
    <div class="post-toc">
        <span>TOC</span>
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#简介"><span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#kubelet-主要功能"><span class="toc-text">kubelet 主要功能</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#pod-管理"><span class="toc-text">pod 管理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#容器健康检查"><span class="toc-text">容器健康检查</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#容器监控"><span class="toc-text">容器监控</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#运行和验证-kubelet"><span class="toc-text">运行和验证 kubelet</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#参数介绍"><span class="toc-text">参数介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#启动-kubelet"><span class="toc-text">启动 kubelet</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#API-接口"><span class="toc-text">API 接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#清理工作"><span class="toc-text">清理工作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#参考链接"><span class="toc-text">参考链接</span></a></li></ol>
    </div>
</div>



        

<aside class="read-next outer">
    <div class="inner">
        <div class="read-next-feed">
            
            

<article class="read-next-card"  style="background-image: url(https://cizixs-blog.oss-cn-beijing.aliyuncs.com/006tNc79ly1g1qxcn9ft3j318w0txdo6.jpg)"  >
  <header class="read-next-card-header">
    <small class="read-next-card-header-sitetitle">&mdash; Cizixs Write Here &mdash;</small>
    <h3 class="read-next-card-header-title">Recent Posts</h3>
  </header>
  <div class="read-next-divider">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
      <path d="M13 14.5s2 3 5 3 5.5-2.463 5.5-5.5S21 6.5 18 6.5c-5 0-7 11-12 11C2.962 17.5.5 15.037.5 12S3 6.5 6 6.5s4.5 3.5 4.5 3.5"/>
    </svg>
  </div>
  <div class="read-next-card-content">
    <ul>
      
      
      
      <li>
        <a href="/2018/08/26/what-is-istio/">什么是 istio</a>
      </li>
      
      
      
      <li>
        <a href="/2018/08/25/knative-serverless-platform/">serverless 平台 knative 简介</a>
      </li>
      
      
      
      <li>
        <a href="/2018/06/25/kubernetes-resource-management/">kubernetes 资源管理概述</a>
      </li>
      
      
      
      <li>
        <a href="/2018/01/24/use-prometheus-and-grafana-to-monitor-linux-machine/">使用 promethues 和 grafana 监控自己的 linux 机器</a>
      </li>
      
      
      
      <li>
        <a href="/2018/01/13/linux-udp-packet-drop-debug/">linux 系统 UDP 丢包问题分析思路</a>
      </li>
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    </ul>
  </div>
  <footer class="read-next-card-footer">
    <a href="/archives">  MORE  → </a>
  </footer>
</article>


            
            
            
        </div>
    </div>
</aside>


<footer class="site-footer outer">

	<div class="site-footer-content inner">
		<section class="copyright">
			<a href="/" title="Cizixs Write Here">Cizixs Write Here</a>
			&copy; 2019
		</section>
		<nav class="site-footer-nav">
			
            <a href="https://hexo.io" title="Hexo" target="_blank" rel="noopener">Hexo</a>
            <a href="https://github.com/xzhih/hexo-theme-casper" title="Casper" target="_blank" rel="noopener">Casper</a>
        </nav>
    </div>
</footer>






<div class="floating-header" >
	<div class="floating-header-logo">
        <a href="/" title="Cizixs Write Here">
			
                <img src="https://cizixs-blog.oss-cn-beijing.aliyuncs.com/006tNc79ly1g1qxfovpzyj30740743yg.jpg" alt="Cizixs Write Here icon" />
			
            <span>Cizixs Write Here</span>
        </a>
    </div>
    <span class="floating-header-divider">&mdash;</span>
    <div class="floating-header-title">kubernetes 简介： kubelet 和 pod</div>
    <progress class="progress" value="0">
        <div class="progress-container">
            <span class="progress-bar"></span>
        </div>
    </progress>
</div>
<script>
   $(document).ready(function () {
    var progressBar = document.querySelector('progress');
    var header = document.querySelector('.floating-header');
    var title = document.querySelector('.post-full-title');
    var lastScrollY = window.scrollY;
    var lastWindowHeight = window.innerHeight;
    var lastDocumentHeight = $(document).height();
    var ticking = false;

    function onScroll() {
        lastScrollY = window.scrollY;
        requestTick();
    }
    function requestTick() {
        if (!ticking) {
            requestAnimationFrame(update);
        }
        ticking = true;
    }
    function update() {
        var rect = title.getBoundingClientRect();
        var trigger = rect.top + window.scrollY;
        var triggerOffset = title.offsetHeight + 35;
        var progressMax = lastDocumentHeight - lastWindowHeight;
            // show/hide floating header
            if (lastScrollY >= trigger + triggerOffset) {
                header.classList.add('floating-active');
            } else {
                header.classList.remove('floating-active');
            }
            progressBar.setAttribute('max', progressMax);
            progressBar.setAttribute('value', lastScrollY);
            ticking = false;
        }

        window.addEventListener('scroll', onScroll, {passive: true});
        update();

        // TOC
        var width = $('.toc-main').width();
        $('.toc-control').click(function () {
            if ($('.t-g-control').css('width')=="50px") {
                if ($('.t-g-control').css('right')=="0px") {
                    $('.t-g-control').animate({right: width}, "slow");
                    $('.toc-main').animate({right: 0}, "slow");
                    toc_icon()
                } else {
                    $('.t-g-control').animate({right: 0}, "slow");
                    $('.toc-main').animate({right: -width}, "slow");
                    toc_icon()
                }
            } else {
                if ($('.toc-main').css('right')=="0px") {
                    $('.toc-main').slideToggle("fast", toc_icon());
                } else {
                    $('.toc-main').css('right', '0px');
                    toc_icon()
                }
            }
        })

        function toc_icon() {
            if ($('.toc-icon').css('display')=="none") {
                $('.toc-close').hide();
                $('.toc-icon').show();
            } else {
                $('.toc-icon').hide();
                $('.toc-close').show();
            }
        }

        $('.gotop').click(function(){
            $('html,body').animate({scrollTop:$('.post-full-header').offset().top}, 800);
        });
        $('.gobottom').click(function () {
            $('html,body').animate({scrollTop:$('.pagination').offset().top}, 800);
        });

        // highlight
        // https://highlightjs.org
        $('pre code').each(function(i, block) {
            hljs.highlightBlock(block);
        });
        $('td.code').each(function(i, block) {
            hljs.highlightBlock(block);
        });

        console.log("this theme is from https://github.com/xzhih/hexo-theme-casper")
    });
</script>



<link rel="stylesheet" href="https://cdn.staticfile.org/lightgallery/1.3.9/css/lightgallery.min.css">



<script src="https://cdn.staticfile.org/lightgallery/1.3.9/js/lightgallery.min.js"></script>


<script>
	$(function () {
		var postImg = $('#lightgallery').find('img');
		postImg.addClass('post-img');
		postImg.each(function () {
			var imgSrc = $(this).attr('src');
			$(this).attr('data-src', imgSrc);
		});
		$('#lightgallery').lightGallery({selector: '.post-img'});
	});
</script>



<script>

/**
*  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
*  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/

var disqus_config = function () {
this.page.url = 'http://cizixs.com/2016/10/25/kubernetes-intro-kubelet/';  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = 'http://cizixs.com/2016/10/25/kubernetes-intro-kubelet/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};

(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://cizixs.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
                            


    </div>
</body>
</html>
